﻿Imports System.Data.SqlClient
Public Class Frm_Execution
    Dim isDateValidate As Boolean = True
    Dim isDateValidate2 As Boolean = True
    Dim pourDate As Date
    Dim deMofa As DictionaryEntry
    
    'Remplissage des zone de la form
    Public Sub remplirZone()
        If Frm_a7kam.avo.remplir_Exec() Then
            With Frm_a7kam.avo.tanfid
                txtNumtanfid.Text = .numExec
                If .dteInscripTribu.Date.Date <> CDate("01/01/0001") Then
                    TextBox1.Text = .dteInscripTribu
                End If

                If .dteExec.Date.Date <> CDate("01/01/0001") Then
                    dteExec.Text = .dteExec
                End If

                TxtObserv.Text = .observation
                Dim i As Integer = 0

            End With
            Partager.moi.List_mofawad.Clear()
        End If
    End Sub

    Private Sub Frm_Execution_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_a7kam.Enabled = True
    End Sub
    Private Sub Frm_Execution_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtNumtanfid.Select()
        remplirZone()

        txtnumDec.Text = Frm_a7kam.avo.Num_decision
    End Sub

    Private Sub btnAjouter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAjouter.Click
        Try
            If Not Frm_a7kam.avo.remplir_Exec() Then ' si la decision n'a pas d'Execrmation
                If txtNumtanfid.Text <> "" And isDateValidate And isDateValidate2 Then
                    If TextBox1.Text = "  /  /" Then
                        pourDate = Nothing
                    Else
                        pourDate = TextBox1.Text
                    End If

                    If MsgBox("هل تريد فعلا إضافة هذاالتنفيذ ؟", MsgBoxStyle.YesNo Or MsgBoxStyle.Information, "إضافة") = MsgBoxResult.Yes Then
                        With Frm_a7kam.avo.tanfid
                            .numExec = txtNumtanfid.Text
                            .dteInscripTribu = pourDate
                            If dteExec.Text = "  /  /" Then
                                pourDate = Nothing
                            Else
                                pourDate = dteExec.Text
                            End If
                            .dteExec = pourDate
                            .resultatExecu = txtResuktaExec.Text
                            .observation = TxtObserv.Text
                        End With
                        Frm_a7kam.avo.Ajouter_Exec()
                        remplirZone()
                        MsgBox("تم الإضافة بنجاح", MsgBoxStyle.Information, "نجاح")
                    End If
                Else
                    MsgBox("لم تدخل رقم التنفيذ أو التاريخ خاطئ", MsgBoxStyle.Critical, "خطأ")
                End If
            Else
                MsgBox("هذا الحكم لديه تنفيذ", MsgBoxStyle.Information, "خطأ")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnmodifier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmodifier.Click
        Try
            If Frm_a7kam.avo.remplir_Exec() Then
                If TextBox1.Text = "  /  /" Then
                    isDateValidate = True
                End If

                If dteExec.Text = "  /  /" Then
                    isDateValidate2 = True
                End If

                If txtNumtanfid.Text <> "" And isDateValidate And isDateValidate2 Then
                    If MsgBox("هل تريد فعلا تعديل هذاالتنفيذ ؟", MsgBoxStyle.YesNo Or MsgBoxStyle.Information, "إضافة") = MsgBoxResult.Yes Then

                        If TextBox1.Text = "  /  /" Then
                            pourDate = Nothing
                        Else
                            pourDate = TextBox1.Text
                        End If


                        With Frm_a7kam.avo.tanfid

                            .numExec = txtNumtanfid.Text
                            .dteInscripTribu = pourDate

                            If dteExec.Text = "  /  /" Then
                                pourDate = Nothing
                            Else
                                pourDate = dteExec.Text
                            End If
                            .dteExec = pourDate

                            .observation = TxtObserv.Text
                        End With
                        Frm_a7kam.avo.modifier_Exec()
                        remplirZone()
                        MsgBox("تم تعديل بنجاح", MsgBoxStyle.Information, "نجاح")
                    End If
                Else
                    MsgBox("لم تدخل رقم التنفيذ أو التاريخ خاطئ", MsgBoxStyle.Critical, "خطأ")
                End If
            Else
                MsgBox("هذا الحكم أو القرار ليس له أي تنفيذ", MsgBoxStyle.Critical, "خطأ")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnSupprimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSupprimer.Click
        Try
            If Frm_a7kam.avo.remplir_Exec Then
                If MsgBox("هل تريد فعلا حذف هذا التنفيذ؟", MsgBoxStyle.YesNo Or MsgBoxStyle.Information, "حذف") = MsgBoxResult.Yes Then
                    Partager.close()
                    Frm_a7kam.avo.suprimmer_Exec()
                    Partager.vider(Me)
                    MsgBox("تم الحذف بنجاح", MsgBoxStyle.Information, "الحذف")
                    isDateValidate = True
                    isDateValidate2 = True
            End If
            Else
                MsgBox("هذا الحكم أو القرار ليس له أي تنفيذ", MsgBoxStyle.Critical, "خطأ")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub TextBox1_TypeValidationCompleted(ByVal sender As Object, ByVal e As TypeValidationEventArgs) Handles TextBox1.TypeValidationCompleted
        If (Not e.IsValidInput) Then
            If TextBox1.Text <> "  /  /" Then
                Me.ToolTip1.ToolTipTitle = "تارخ خاطئ !"
                Me.ToolTip1.Show("أدخل التاريخ على هذا الشكل: السنة/الشهر/اليوم", Me.TextBox1, 0, -50, 5000)
                isDateValidate = False
            End If

            If TextBox1.Text = "  /  /" Then
                isDateValidate = True
            End If
        Else
            isDateValidate = True
        End If
    End Sub

    Private Sub dteExec_TypeValidationCompleted(ByVal sender As Object, ByVal e As TypeValidationEventArgs) Handles dteExec.TypeValidationCompleted
        If (Not e.IsValidInput) Then
            If dteExec.Text <> "  /  /" Then
                Me.ToolTip1.ToolTipTitle = "تارخ خاطئ !"
                Me.ToolTip1.Show("أدخل التاريخ على هذا الشكل: السنة/الشهر/اليوم", Me.dteExec, 0, 40, 5000)
                isDateValidate2 = False
            End If
            If dteExec.Text = "  /  /" Then
                isDateValidate2 = True
            End If
        Else
            isDateValidate2 = True
        End If
    End Sub

    Private Sub txtNumtanfid_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Dim allowedChars As String = "1234567890/"
        If e.KeyChar = ChrW(8) Then
            e.Handled = False
        ElseIf allowedChars.IndexOf(e.KeyChar) = -1 Then
            ' Invalid Character
            e.Handled = True
        End If
    End Sub

    Private Sub txt_DureeDappel_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Dim allowedChars As String = "1234567890/"
        If e.KeyChar = ChrW(8) Then
            e.Handled = False
        ElseIf allowedChars.IndexOf(e.KeyChar) = -1 Then
            ' Invalid Character
            e.Handled = True
        End If
    End Sub

End Class